/*
 *  Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the License); you may
 *  not use this file except in compliance with the License.
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmssl/sm2.h>
#include <gmssl/rand.h>

/*
void gen_point(void)
{
	SM2_KEY sm2_key;
	size_t i;
	uint8_t *p = &sm2_key;

	sm2_key_generate(&sm2_key);
	for (i = 0; i < 64; i++) {
		printf("0x%02x,", p[i]);
	}
	printf("\n");
}
*/

int main(void)
{
	SM2_POINT P;
	uint8_t bin[64] = {
		0x0e,0x90,0x75,0x97,0x92,0x4f,0x48,0x6d,
		0x9f,0xa9,0x58,0x63,0xeb,0xb2,0x7b,0xa5,
		0xd2,0xc7,0x77,0x64,0x2c,0x94,0x8f,0x32,
		0xda,0x3a,0xd6,0xef,0xef,0xe4,0xda,0xaf,
		0x41,0x70,0x92,0x65,0x4f,0xf8,0x81,0x57,
		0x70,0x83,0x00,0xab,0x71,0xae,0xb0,0xaf,
		0x7b,0x55,0xe1,0x45,0xc7,0x9d,0xfb,0xcc,
		0xf4,0x10,0xff,0xe3,0x32,0xc4,0xcb,0x07,
	};

	if (sm2_point_from_xy(&P, bin, bin + 32) != 1) {
		fprintf(stderr, "sm2_point_from_xy() error\n");
		goto err;
	}
	sm2_point_print(stdout, 0, 0, "SM2_POINT", &P);

	rand_bytes(bin, 64);

	if (sm2_point_from_xy(&P, bin, bin + 32) != 1) {
		fprintf(stderr, "sm2_point_from_xy() error on random data\n");
		goto err;
	}

err:
	return 0;
}
